|
|
|
|
|
|
|
projection through a pixel until it hits an object. It examines each object in the scene to find the one with the smallest value t returned by FindT. It then uses that object's FindHitColor routine to decide what color to make the pixel. |
|
|
|
 |
|
|
|
|
' Return the pixel color given by tracing from
' point (px, py, pz) in direction <vx, vy, vz>. Public Sub TraceRay(ByVal direct_calculation As Boolean, _
ByVal depth As Integer, _
ByVal skip_object As RayTraceable, ByVal px As Single, _
ByVal py As Single, ByVal pz As Single, _
ByVal Vx As Single, ByVal Vy As Single, _
ByVal Vz As Single, ByRef R As Integer, _
ByRef G As Integer, ByRef B As Integer)
Dim obj As RayTraceable
Dim best_obj As RayTraceable
Dim best_t As Single
Dim t As Single
' Find the object that's closest. best_t = INFINITY
For Each obj In Objects ' Skip the object skip_object. We use this
' to avoid erroneously hitting the object
' casting out a ray. If Not (obj Is skip_object) Then
t = obj.FindT(direct_calculation, px, py, pz, _
Vx, Vy, Vz)
If (t > 0) And (best_t > t) Then
best_t = t
Set best_obj = obj
End If
End If
Next obj
' See if we hit anything. If best_obj Is Nothing Then ' We hit nothing. Return the background color. R = BackR
G = BackG
B = BackB
Else ' Compute the color at that point. best_obj.FindHitColor depth, Objects, _
px, py, pz, _
px + best_t * Vx, _
py + best_t * Vy, _
pz + best_t * Vz, _
R, G, B
' This is a problem for some values of Kdist. If R < 0 Then R = 0 |
|
|
|
|
|